package com.imessage.action.no.group;

import com.bean.BusinessGroup;
import com.bean.BusinessUsePhone;
import com.imessage.action.BaseAction;
import com.imessage.type.BaseState;
import com.imessage.vo.GroupVo;
import com.imessage.vo.UsePhoneVo;
import io.ebean.Expr;
import io.ebean.Expression;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;


public class GroupBaseAction extends BaseAction {

    protected final String datagrid = "datagrid-businessGroup-filter";


    protected void setExpressionList(List<Expression> expressionList, GroupVo groupVo) {
        if (StringUtils.isNotBlank(groupVo.getName())) {
            expressionList.add(Expr.contains("name", groupVo.getName()));
        }
    }


    protected void setModelAndView(ModelAndView modelAndView, BusinessGroup group) {
        modelAndView.addObject("usePhoneGroupForm", group);
        modelAndView.addObject("statusList", BaseState.values());
    }

    protected void setBusinessGroup(GroupVo groupVo, BusinessGroup group) {
        copyProperties(groupVo, group);
        if (StringUtils.isNotBlank(groupVo.getState())) {
            group.setState(BaseState.fromValue(groupVo.getState()));
        }
    }


}
